package com.vcredit.creditcat.web.h5;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.vcredit.creditcat.api.product.h5.IRepaymentManager;
import com.vcredit.creditcat.dto.product.h5.RepaymentBillPageData;
import com.vcredit.creditcat.dto.product.h5.RepaymentDto;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.vo.JsonResult;
import com.vcredit.creditcat.web.app.BaseCreditCatController;
import com.vcredit.framework.annotation.Log;

@RestController
@RequestMapping("repayment")
public class RepaymentController extends BaseCreditCatController{
	private static final Logger LOG = LoggerFactory.getLogger(RepaymentController.class);
	private static final String ERROR_MSG = "系统异常，请稍后再试";
	@Reference(version = "1.0")
	private IRepaymentManager repaymentManager;
	/**
	 * 主动还款 + 主动还款验证码
	 * @author zhaoqi01
	 * @param productId
	 * @param param
	 * @param request
	 * @return
	 */
	@Log
	@RequestMapping("{productId}/repayment")
	public JsonResult<RepaymentDto> repayment(@PathVariable("productId") Long productId,
			@RequestBody RepaymentDto param, HttpServletRequest request) {
		Cust cust = new Cust();
		try {
			cust = getCust(request);
			RepaymentDto result = repaymentManager.repayment(cust,productId,param);
			return JsonResult.SuccessResponse(result);
		} catch (Exception e) {
			LOG.error("------------贷款放贷主动还款异常!! productId = "+productId+", custId=" + cust.getCustId(),e);
		}
		return JsonResult.ErrorResponse(ERROR_MSG);
	}
	
	@Log
	@RequestMapping("/repaymentBillList")
	public JsonResult<RepaymentBillPageData> repaymentBillList(HttpServletRequest request) {
		Cust cust = new Cust();
		try {
			cust = getCust(request);
			RepaymentBillPageData result = repaymentManager.queryRepaymentplan(cust);
			return JsonResult.SuccessResponse(result);
		} catch (Exception e) {
			LOG.error("------------查询还款计划异常!! custId=" + cust.getCustId(),e);
		}
		return JsonResult.ErrorResponse(ERROR_MSG);
	}
}
